<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="/common/user.jsp"%>
<%
    /*Integer uid = token.getUid();
    List<Map> visits = QBuilder.db("basedb").select("new map(v.id as visit_id, v.name as patient_name, v.isconfirmed as confirm, v.surveyId as survey_id,v.checkTime as check_time, v.sendTime as send_time, sq.title as title)").from("Visit as v, SurveyQuestion as sq").where(new Where("v.hospital=", hospital).and("v.status = ", STATUS_ENABLE).and("v.category=2").and("v.patientUid=", uid)).order("v.cTime", QBuilder.desc).query().getResultObj();
    Date date = new Date();
    Long min = Long.MAX_VALUE;
    Map minVisit = null;
    List<Map> upVisit = new ArrayList<Map>();
    for (int i = 0; i < visits.size(); i++) {
        Map map = visits.get(i);
        String checkTime = Tools.getDesc(map.get("check_time"),"");
        if ("".equals(checkTime)) continue;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		try {
			Date d = sdf.parse(checkTime);
            Long _min = d.getTime() - date.getTime();
            if (_min > 0) {
                upVisit.add(map);
                if (min > _min) {
                    min = _min;
                    minVisit = map;
                }
            }
		} catch (ParseException e) {
			e.printStackTrace();
		}
    }
    //visits.removeAll(upVisit);
    //if (!isEmpty(minVisit))
    //    visits.add(0, minVisit);
    if (isEmpty(visits)) {
        msg = new Message(30041, "暂无随访计划");
    }
    msg.put("data", visits);
    Tools.encryptPrint(out, msg);*/

    Integer uid = token.getUid();
    List<Map> visits = QBuilder.db("basedb").select("new map(v.id as visit_id, v.name as patient_name, v.isconfirmed as confirm, v.surveyId as survey_id, v.patientUid as patient_uid, v.sendTime as send_time, s.title as title, u.name as doctor_name)").from("Visit as v, Survey as s, User as u").where(new Where("v.hospital=", hospital).and("v.status = ", STATUS_ENABLE).and("s.hospital=", hospital).and("s.status = ", STATUS_ENABLE).and("v.category=2").and("s.category=2").and("v.patientUid=", uid).and("s.id = v.surveyId").and("u.id = v.doctorUid")).order("v.cTime", QBuilder.desc).query().getResultObj();
    if (isEmpty(visits)) {
        msg = new Message(30041, "暂无随访计划");
    }
    User user = userByUid(uid);
    for (int i = 0; i < visits.size(); i++) {
        Map map = visits.get(i);
        map.put("patient_name", user.getName());
    }
    msg.put("data", visits);
    Tools.encryptPrint(out, msg);
%>
